package com.zw.admin.server.job;

import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.springframework.context.ApplicationContext;
import org.springframework.scheduling.quartz.QuartzJobBean;

import com.zw.admin.server.config.JobConfig;
import com.zw.admin.server.service.JobService;

/**
 *
 1、调度工作类：org.springframework.scheduling.quartz.JobDetailFactoryBean，该对象通过jobClass属性指定调度工作类(做什么)；

 2、调度触发器：org.springframework.scheduling.quartz.CronTriggerFactoryBean，该对象通过jobDetail属性指定工作类，通过
 cronExpression属性指定调度具体的时间及频率(什么时候做)；

 3、调度工厂类：org.springframework.scheduling.quartz.SchedulerFactoryBean，该对象通过triggers属性指定单个或多个触发器(调度安排)。

 */
public class SpringBeanJob extends QuartzJobBean {

	@Override
	protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
		try {
			ApplicationContext applicationContext = (ApplicationContext) context.getScheduler().getContext()
					.get(JobConfig.KEY);
			JobService jobService = applicationContext.getBean(JobService.class);
			jobService.doJob(context.getJobDetail().getJobDataMap());
		} catch (SchedulerException e) {
			e.printStackTrace();
		}
	}

}
